{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Install FuxiCTR\n",
    "\n",
    "```{note}\n",
    "The tutorial is for FuxiCTR v1.0.\n",
    "```\n",
    "\n",
    "FuxiCTR has the following requirements.\n",
    "\n",
    "+ python 3.6\n",
    "+ pytorch v1.0/v1.1\n",
    "+ pyyaml >=5.1\n",
    "+ scikit-learn\n",
    "+ pandas\n",
    "+ numpy\n",
    "+ h5py\n",
    "+ tqdm\n",
    "\n",
    "We recommend to install the above enviornment through Anaconda using [Anaconda3-5.2.0-Linux-x86_64.sh](https://link.zhihu.com/?target=https%3A//mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.2.0-Linux-x86_64.sh). \n",
    "\n",
    "There are two ways to install FuxiCTR v1.0.x.\n",
    "\n",
    "**Solution 1**: pip install (note that all dependent requirements need to be installed accordingly.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: fuxictr==1.0.* in c:\\users\\qiqi\\anaconda3\\lib\\site-packages (1.0.2)\n",
      "Requirement already satisfied: pandas in c:\\users\\qiqi\\anaconda3\\lib\\site-packages (from fuxictr==1.0.*) (0.23.0)\n",
      "Requirement already satisfied: scikit-learn in c:\\users\\qiqi\\anaconda3\\lib\\site-packages (from fuxictr==1.0.*) (0.19.1)\n",
      "Requirement already satisfied: h5py in c:\\users\\qiqi\\anaconda3\\lib\\site-packages (from fuxictr==1.0.*) (2.7.1)\n",
      "Requirement already satisfied: numpy in c:\\users\\qiqi\\anaconda3\\lib\\site-packages (from fuxictr==1.0.*) (1.14.3)\n",
      "Requirement already satisfied: tqdm in c:\\users\\qiqi\\anaconda3\\lib\\site-packages (from fuxictr==1.0.*) (4.62.3)\n",
      "Requirement already satisfied: PyYAML in c:\\users\\qiqi\\anaconda3\\lib\\site-packages (from fuxictr==1.0.*) (3.12)\n",
      "Requirement already satisfied: pytz>=2011k in c:\\users\\qiqi\\anaconda3\\lib\\site-packages (from pandas->fuxictr==1.0.*) (2018.4)\n",
      "Requirement already satisfied: python-dateutil>=2.5.0 in c:\\users\\qiqi\\anaconda3\\lib\\site-packages (from pandas->fuxictr==1.0.*) (2.7.3)\n",
      "Requirement already satisfied: six in c:\\users\\qiqi\\anaconda3\\lib\\site-packages (from h5py->fuxictr==1.0.*) (1.11.0)\n",
      "Requirement already satisfied: colorama; platform_system == \"Windows\" in c:\\users\\qiqi\\anaconda3\\lib\\site-packages (from tqdm->fuxictr==1.0.*) (0.4.4)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "distributed 1.21.8 requires msgpack, which is not installed.\n"
     ]
    }
   ],
   "source": [
    "!pip install fuxictr==1.0.*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Solution 2**: git clone or download the zip file: https://github.com/xue-pai/FuxiCTR/archive/refs/tags/v1.0.2.zip\n",
    "\n",
    "If you download the source code, you need to add the fuxictr folder to the system path in your code."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append('./YOUR_PATH/fuxictr')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Check if fuxictr has been installed successfully."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1.0.2'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import fuxictr\n",
    "fuxictr.__version__"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Run the tests:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!cd tests\n",
    "!bash test_all.sh\n",
    "!bash test_all_gpu.sh # if GPU is available"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
